@file:JvmName("FloatExtensions")
package com.example.mytestdemo.extensions

import android.content.res.Resources

/**
 * Created on 2020/8/18,@author Zen.
 * E-mail:jyzen@foxmail.com
 * This is ground control to Major Tom.
 * Don't panic.
 */

/**
 * 转dp
 */
val Float.dp: Int
    get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()

/**
 * 转sp
 */
val Float.sp: Int
    get() = (this * Resources.getSystem().displayMetrics.scaledDensity + 0.5f).toInt()

/**
 * 获取安全Float值
 */
fun Float?.safe(default: Float = 0f): Float {
    return this ?: default
}